package com.qingke.login;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.ibatis.session.SqlSession;
import com.qingke.mapper.UserMapper;
import com.qingke.sqlclass.User;

@WebServlet("/MessageServlet")
public class UserListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public UserListServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<String> userlist = (List<String>) request.getServletContext().getAttribute("userlist");
		List<User> user = selectUserlist();
		for (User user2 : user) {
			userlist.addAll((Collection<? extends String>) user2);
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	public static List<User> selectUserlist(){
		SqlSession session = LoginDao.getMybatisSession();
		UserMapper usermap = session.getMapper(UserMapper.class);
		List<User> user = usermap.selectAll();
		return user;
	}
	
}
